<template>
  <div>
    <mt-field label="手机号" placeholder="请输入账号" type="tel" v-model="number"></mt-field>
    <mt-field label="密码" placeholder="请输入密码" type="password" v-model="password" ></mt-field>
    <!--<router-link to="/">-->
      <mt-button type="default" class="set-button1" @click="HandleLogin">登陆</mt-button>
    <!--</router-link>-->
    <mt-button type="default" class="set-button2" @click="btnChange">重置</mt-button>
    <router-link to="/Register">
      <div>忘记密码？</div>
    </router-link>
    <router-link to="/Register">
      <div>创建帐号</div>
    </router-link>
    <div>
      <div>{{this.number}}</div>
      <div>{{this.password}}</div>
    </div>
  </div>
</template>

<script>
  import { Button } from 'mint-ui';
  import { Field } from 'mint-ui';
  import { MessageBox } from 'mint-ui';
  import axios from 'axios';
  import qs from 'qs';
  export default {
    name: "LoginContent",
    components:{
      MtField:Field,
      MtButton:Button,
    },
    data:function () {
      return{
        password:'',
        number:'',
        userObject:null,
        classObject:null,
        studentId:'',
      }
    },
    methods:{
      btnChange:function () {
        this.email = '';
        this.password = '';
        this.number = '';
      },
      HandleLogin:function(){
        var _this = this;
        axios.post('http://www.thinkingfastandslow.xyz:8080/sas-manager-web/login',
          qs.stringify({username:this.number,password:this.password}))
          .then(this.getLoginInfoSucc)
          .catch(err => {
            console.log(err);
          });},
      getLoginInfoSucc:function (res) {
        this.userObject = res;
        console.log(this.userObject.data);
        if(this.userObject.data[0] === 'success'){
          this.$store.state.name = this.userObject.data[1].name;
          console.log("登陆成功");
          // console.log(this.userObject.data[1].name);
          this.studentId = this.userObject.data[1].studentId;
          this.$router.push('/home');
          axios.post('http://www.thinkingfastandslow.xyz:8080/sas-manager-web/prosceniumStudentController/selectAllOpenAttendanceCourse'
            ,qs.stringify({studentid:this.studentId,isattendance:0}))
            .then(this.getLoginInfoSucc2)
            .catch(err => {
              console.log(err);
            });
        }
      },

      getLoginInfoSucc2:function (res) {
        console.log(res.data);
        this.classObject = res.data;
        if(this.classObject.msg === '获取成功'){
          if(this.classObject.data.length == 0){
            MessageBox("当前无可签到课程");
          }
        }
      }
    },
    mounted () {

    }
  }
</script>

<style scoped>
  .set-button1{
    margin-top: 1rem;
    margin-left: 0rem;
    margin-right: 6.5rem;

  }
  .set-button1{
    margin-top: 1rem;
    margin-right: 3rem;
  }
</style>
